using System.Collections.Generic;

namespace Charisma.Tests.Models.BlogApp
{
    public class BlogAppContext : DbContext
    {
        public BlogAppContext()
            : base("Test")
        {
        }

        public Repository<Person> Persons { get; set; }

        public Repository<Blog> Blogs { get; set; }

        // Example of full model registration: no conventions, no magic
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
//            modelBuilder.Repository<BlogAppContext, Person>(c => c.Persons)
//                .HasKeyMember(p => p.Id)
//                .HasName("PersonCollection");
//        .HasKeyGenerator(() => new StringKeyGenerator());

//            modelBuilder.Repository(c => c.Blogs)
//                .HasKeyMember(b => b.Id)
//                .HasName("BlogCollection");
//        .HasKeyGenerator(() => new StringKeyGenerator());;

            modelBuilder.Entity<Person>()
                .Map(p => p.FirstName)
                .Map(p => p.LastName)
                .Map(p => p.Contacts)
                .Ignore(p => p.FullName); // calculated property

            modelBuilder.Entity<Author>()
                .Map(a => a.Nickname)
                .Ignore(a => a.Titles);

            modelBuilder.Entity<Post>()
                .Map(p => p.Date)
                .Map(p => p.Content)
                //                .Map(p => p.Comments).HasInitializer(p => new List<Comment>())
                .Map(p => p.Title);
//                .Map(p => p.Tags).HasInitializer(p => new List<string>());

            modelBuilder.Entity<Blog>()
                .Map(b => b.Title)
                .Map(b => b.AuthorId);
            //                .Map(b => b.Author).HasBackingStorage(b => b.AuthorId, a => a.Id)
            //                .Map(b => b.Posts).HasInitializer(b => new List<Post>());
        }
    }
}